import json
from autotest.core.logger import logger

def wsInterface(self, session, url, params=None, verify=False, headers=None, **kwargs):
    """
    封装的ws项目http请求方法，接受session url, param, method， verify, headers 发起http请求并返回json
    :param session: requests session 对象
    :param url: 请求地址
    :param param: 请求参数 形如{key1:value1, key2:value2}
    :param method: 请求方式 默认post
    :param verify: ssl检验 默认关
    :param headers: http headers
    :return: 接口返回内容/None
    """
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3423.2 Safari/537.36"}

    logger.info(f'开始调用接口:{url},参数为:params:{params},kwargs:{kwargs}')
    returnJson = None
    if params:
        assert isinstance(params, dict), 'params必须为Dict'
        params.update(kwargs)
    else:
        params = kwargs
    theParam = f'{{"head":{{"clientId":"12","appUDID":"","appVersion":"","channelId":"",' \
               f'"innerMedia":"","outerMedia":"","subClientId":"h5"}},"body":{json.dumps(params)}}}'
    logger.info(f"请求参数：{theParam}")
    res = session.post(url, data={'params': theParam}, verify=verify, headers=headers)
    logger.info(f'response.status_code:{res.status_code}')
    if res.status_code == 200:
        try:
            returnJson = res.json()
        except (TypeError, json.JSONDecodeError) as e:
            logger.error(f'请求接口:{url}出错,返回:{res.text}\n报错:{e}')
    else:
        logger.error('请求接口失败！响应码非200！')
    logger.debug(f'接口:{url},参数params:{params},kwargs:{kwargs},调用完成 返回:{returnJson}')
    return returnJson